package lesson2;

import java.io.File;
import java.io.IOException;

public class Demo1 {
    public static void main(String[] args) throws IOException {
        //File file1 = new File("C:\\Users\\Administrator\\Desktop\\TestFile\\1.txt");
        File file1 = new File("file\\1.txt");
        //可以通过File对象获取文件的一切信息,除了文件内容
        //文件名称
        String fileName = file1.getName();
        //文件路径
        //获取相对路径
        String filePath1 = file1.getPath();
        //获取绝对路径
        String filePath2 = file1.getAbsolutePath();
        System.out.println(fileName);
        System.out.println(filePath1);
        System.out.println(filePath2);

        //获取文件大小
        long fileSize = file1.length();
        System.out.println(fileSize);
        System.out.println("*************************");
//        File file2 = new File("file/123.txt");
//        boolean isExists = file2.exists();
//        System.out.println(isExists);
//        file2.createNewFile();
        File file2 = new File("file/file/123.txt");
        if(file2.exists()){
            file2.delete();
        }else{
            file2.createNewFile();
        }



    }

}
